using System;
using System.IO;

namespace ERP.Classes
{
	/// <summary>
	/// Summary description for csFileIO.
	/// </summary>
	public class csFileIO
	{
		private string filepath;
		private string content;
		public csFileIO()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		public string FilePath
		{
			get{ return this.FilePath;}
			set{ this.filepath = value;}
		}
		public string Content
		{
			get{ return this.content;}
			set{ this.content = value;}
		}

		public int SaveToFile()
		{
			FileStream fs = new FileStream(this.filepath,
				FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);

			StreamWriter mySW = new StreamWriter(fs,System.Text.Encoding.UTF8);
			try
			{
				//mySW = File.Open(this.filepath, );
				mySW.Write(this.content);
				mySW.Flush();
				mySW.Close();
				return 1;
			}
			catch
			{
				return -1;
			}
		}
		public int ReadFile()
		{
			try 
			{
				// Create an instance of StreamReader to read from a file.
				// The using statement also closes the StreamReader.
				using (StreamReader sr = new StreamReader(this.filepath)) 
				{
					this.content = sr.ReadToEnd();
					sr.Close();
					return 1;
				}
			}
			catch
			{
				return -1;
			}

		}
	}
}
